<%@ page import="top.fyxxxx.dbdesign.dao.DBoperate" %>
<%@ page import="java.util.Set" %>
<%@ page import="top.fyxxxx.dbdesign.data.Course" %>
<%@ page import="java.util.List" %>
<%@ page import="top.fyxxxx.dbdesign.data.TaskData" %>
<%@ page import="top.fyxxxx.dbdesign.data.SignInTask" %>
<%@ page import="top.fyxxxx.dbdesign.util.QueryModule" %>
<%@ page import="top.fyxxxx.dbdesign.data.SignInRecord" %>
<%@ page import="top.fyxxxx.dbdesign.util.Reporter" %>
<%@ page import="top.fyxxxx.dbdesign.util.CourseManager" %>
<%@ page import="top.fyxxxx.dbdesign.util.Manager" %>
<%--
  Created by IntelliJ IDEA.
  User: WZL
  Date: 2020/5/4
  Time: 23:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员主页</title>
    <link rel="stylesheet" type="text/css" href="inf.css">
    <link rel="stylesheet" type="text/css" href="bar.css">
    <link rel="stylesheet" type="text/css" href="boxAndButton.css">
</head>
<body  style="text-align: center">
<script src="ajax1.js"></script>
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    DBoperate dBoperate=DBoperate.getInstance();
    QueryModule reporter=Reporter.getInstance();
    CourseManager courseManager= Manager.courseManager();
    if(session.getAttribute("uid")==null)request.getRequestDispatcher("/index.jsp").forward(request,response);
    long uid=(Long)session.getAttribute("uid");
    //long uid=1590064934429L;
    //session.setAttribute("uid",uid);
%>
    <div class="createClassBox" >
        <button   type="submit" value="提交" onclick="location='searchClass.jsp'">发布签到任务</button>
    </div>

    <div class="createClassBox" >
        <button   type="submit" value="提交" onclick="location='createClass.jsp'">创建/加入班级</button>
    </div>
    <div class="createClassBox" >
        <button   type="submit" value="提交" onclick="location='studentMainPage.jsp'">签到</button>
    </div>
    <div class="logoutBox" >
        <button   type="submit" value="提交" onclick="location='index.jsp?un=1'">注销</button>
    </div>
<%

    List<Course> cidSet=courseManager.getPowerCourse(uid);
    System.out.print(cidSet);
    for (Course course:cidSet){
        //System.out.println(cid);
        long cid=course.getCid();
%>

<div id="content"  style="text-align: left;margin-top: 10px">
    <div style="text-align: center">
        <p class="title"><%=course.getName()%></p>
        <div class="deleteBox" >
            <button    onclick="
                location='DeleteServlet?cid=<%=cid%>'
            "><%=(course.getCreateByUid()==uid)?"删除课程":"退出课程"%></button>
        </div>
        <div class="deleteBox"  style="float: left">
            <button    onclick="
                    location='classMember.jsp?cid=<%=cid%>'
                    ">查看班级学生</button>
        </div>
        <br><br><hr>
    </div>

    <%
        List<TaskData> taskDataList= reporter.getTasksData(uid,cid);
        int j=0;
        //System.out.print(uid);
        //System.out.print(cid);
        //System.out.print(taskDataList);
        for(TaskData taskData:taskDataList){
            String t="";
            List<String> nameList=taskData.getUnSignInNames();
            double process=(double)taskData.getSignInNum()/taskData.getTotal()*100;
            if(taskData.getTotal()==0)process=100;
            if (process<60-1e-8)t="red";
            else if(process<100-1e-8)t="yellow";
            else t="green";
    %>
            <div style="margin-top: 30px">
                <a style="text-decoration:none" href="assignments.jsp?sid=<%=taskData.getTask().getSid()%>&cid=<%=cid%>">签到任务<%=++j%></a>
                <p style="font-size: 10px;float: right">签到人数:<%=taskData.getSignInNum()%>人  未签到人数<%=taskData.getUnSignInNum()%>人</p>
                <br>
                <div class="progress">
                    <span class="<%=t%>" style="width: <%=process%>%"><span><%=process%>%</span></span>
                </div>
                <div style="margin-top: 5px">
                    <p class="mainBody">
                    未签到名单：
<%
            for(String name:nameList){
                out.print(name+"  ");
            }
%>                  </p>
                </div>
            </div>

<%
        }
%>
</div>
<br>
<br>
<%
    }
%>

</body>
</html>
